package com.dianwoba.core.redis.serializer;

import org.springframework.data.redis.serializer.SerializationException;

import com.fasterxml.jackson.core.type.TypeReference;

/**
 * 
 * @author Administrator
 *
 * @param <T>
 */
public interface RedisSerializer<T> {

	/**
	 * Serialize the given object to binary data.
	 * 
	 * @param t object to serialize
	 * @return the equivalent binary data
	 */
	byte[] serialize(T t) throws SerializationException;

	/**
	 * Deserialize an object from the given binary data.
	 * 
	 * @param bytes object binary representation
	 * @return the equivalent object instance
	 */
	T deserialize(byte[] bytes) throws SerializationException;
	
	/**
	 * Deserialize an object from the given binary data.
	 * 
	 * @param bytes object binary representation
	 * @param clazz the class of return object
	 * @return
	 * @throws SerializationException
	 */
	<V> V deserialize(byte[] bytes, Class<V> clazz) throws SerializationException;
	
	/**
	 * Deserialize an object from the given binary data.
	 * 
	 * @param bytes object binary representation
	 * @param valueTypeRef the value type of return object
	 * @return
	 * @throws SerializationException
	 */
	<V> V deserialize(byte[] bytes, TypeReference<?> valueTypeRef) throws SerializationException;
}
